package de.tu_darmstadt.gdi1.towerdefense.model.monstermodel;

import java.awt.Point;

import de.tu_darmstadt.gdi1.towerdefense.model.mapmodel.AMap;
import de.tu_darmstadt.gdi1.towerdefense.model.mapmodel.WayPoint;
import de.tu_darmstadt.gdi1.towerdefense.model.playermodel.PlayerModel;

public abstract class Monster {

	/**
	 * The name of a Monster for Image
	 */
	private String NameOfMonster;
	/**
	 * The LivePoints of a monster
	 */
	private int livePoints;
	/**
	 * the damage of a Monster
	 */
	private int damage;
	/**
	 * the x and y coordinate of a Monster
	 */
	private Point position = new Point();
	/**
	 * the money that the Monster give it is death
	 */
	private int creditsOfMonster;

	/**
	 * to add a monster with variable points
	 * @param livePoint
	 * @param damageOfMonster
	 * @param money
	 * @param NameOfMonster
	 */
	public Monster(int livePoint, int damageOfMonster, int credits,
			String monsterName) {
		livePoints = livePoint;
		damage = damageOfMonster;
		creditsOfMonster = credits;
		NameOfMonster = monsterName;

	}

	/**
	 * 
	 * @return String of Monsters name
	 */
	public String getMonsterName() {
		return NameOfMonster;
	}

	/**
	 * get the current livePoints of the monster
	 * 
	 * @return livePoints of Monster
	 */
	public int getLivePoints() {
		return livePoints;
	}

	/**
	 * set the livePoints of a monster
	 * 
	 * @param livePoints
	 */
	public void setLivePoints(int livePoints) {
		this.livePoints = livePoints;
	}

	/**
	 * the damage that the monster can do
	 * 
	 * @return damage of a monster
	 */
	public int getDamage() {
		return damage;
	}

	/**
	 * set the damage of the monster
	 * 
	 * @param damage
	 */
	public void setDamage(int damage) {
		this.damage = damage;
	}

	public int getCreditsOfMonster() {
		return creditsOfMonster;
	}

	/**
	 * 
	 * @return the X Y position of a Monster
	 */
	public Point getPositon() {
		return position;
	}

	/**
	 * set the x and y coordinate
	 * 
	 * @param x
	 * @param y
	 */
	public void setPoint(int x, int y) {
		position.x = x;
		position.y = y;
	}

	/**
	 * 
	 * @return the damage of a monster
	 */
	public abstract int monsterDamage();

	/**
	 * 
	 * @return the speed of a Monster
	 */
	public abstract void monsterSpeed();

	/**
	 * 
	 * @return the livePoint of a monster
	 */
	public abstract int monsterLivePoints();

	/**
	 * send the money to the player
	 * 
	 * @return
	 */
	public abstract int getCreditsOfMonsterToPlayer();

	/**
	 * remove a monster from a Map
	 * 
	 * @param a
	 *            AMap
	 */
	public void removeMonster(AMap a) {
		a.removeMonsterFromMap(getPositon().x, getPositon().y);
	}

	/**
	 * if the monster is Dedth it returns fkae
	 * 
	 * @param a
	 *            AMap
	 * @param p
	 *            PlaerModel
	 * @return boolean
	 */
	public boolean isMonsterDead(AMap a, PlayerModel p) {
		if (getLivePoints() <= 0) {
			a.removeMonsterFromMap(position.x, position.y);
			p.addCredits(getCreditsOfMonsterToPlayer());
			return true;
		}
		return false;
	}

	/**
	 * move one monster one step for one tick
	 * 
	 * @param a
	 *            AMap
	 * @param p
	 *            PlacerModel
	 */
	public void moveMonster(AMap a, PlayerModel p) {
		// if( solot89 == true){// TODO
		for (int i = 0; i < a.getWaypoint().size(); i++) {
			WayPoint wp = new WayPoint(a.getWaypoint().get(i).getxCoord(), a
					.getWaypoint().get(i).getyCoord());

			if (getPositon().x == wp.getxCoord()
					&& getPositon().y == wp.getyCoord()) {

				if (i != a.getWaypoint().size() - 1) {
					a.setMonsterPosition(
							a.getWaypoint().get(i + 1).getxCoord(), a
									.getWaypoint().get(i + 1).getyCoord());
					setPoint(a.getWaypoint().get(i + 1).getxCoord(), a
							.getWaypoint().get(i + 1).getyCoord());

					if ('X' == a.getOriginalMap()[getPositon().y][getPositon().x]) {
						p.setDamage(getDamage());
						a.removeMonsterFromMap(getPositon().x, getPositon().y);
						setPoint(0, 0);
						setLivePoints(0);
					}
					break;
				}
			}
		}
	}

	/**
	 * set the money of the monster
	 * @param i money
	 */
	public void setMoney(int i) {
		creditsOfMonster = i;

	}
}
